#ifndef __FILTER_WINDOW_H__
#define __FILTER_WINDOW_H__

#include <string>
#include <vector>
#include <cv.h>
#include "Picture.h"
#include "Filter.h"

#define MAX_WIDTH  800
#define MAX_HEIGHT 600

#define BLACK cv::Scalar(0,0,0)
#define GREEN cv::Scalar(0,255,0)
#define RED   cv::Scalar(0,0,255)


void globalMouseCallback( int event, int x, int y, int flags, void* param );

class FilterWindow {
    public:
        /*
        NO_MOUSE - The filter will not get user interaction
        LAST_CLICK - The filter will recieve one Point(x,y) 
                     indicating the last position specified by the user
        DRAW - The filter will get cv::Mat filled with cv::GC_BGD/GC_FGD or NOTHING

        ** in Picture.h - #define NOTHING
 
        */
        enum MouseBehavior{
            NO_MOUSE,
            LAST_CLICK,
            DRAW
        };
        /* Window is changing filter's properties */
        FilterWindow(Filter& f, string window_name = string("Filter"), MouseBehavior mb=NO_MOUSE);
        ~FilterWindow();

        void refresh();
        unsigned loop(unsigned int timeout = 180);
        /* Adds a green rect arround the each of the gives Rects*/
		void highlight(vector<cv::Rect> ROIs);
        /* Internal methods: used by globalMouseCallback */
        void _mouseCallbackLastClick( int event, int x, int y, int flags );
        void _mouseCallbackDraw( int event, int x, int y, int flags);
        MouseBehavior _getMouseBehavior() { return mb; }
    private:
        /* Mouse state */
        MouseBehavior mb;
        cv::Point lastClick;
        bool leftDown, rightDown;
        /* Image state */
        string windowName;
		cv::Mat latestDisplayed;
		cv::Mat latestNormalized;
        /* helper function used when in MouseBehavior = DRAW MODE */
        void setPixelOnMask( uchar mode, int x, int y);
        Filter& filter;
        cv::Mat userMask;
        /* If image is resized the ratio is saved in ratio (otherwise it ratio=1) */
        double ratio;
		void displayNormalized(cv::Mat& disp);
};

#endif // __FILTER_WINDOW_H__
